package com.offcn.utils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;

public class FileUploadUtil {
    public static String fileUpload(HttpServletRequest req) throws IOException, ServletException {
        Part part = req.getPart("file");
        String fileName = part.getSubmittedFileName();
        fileName = System.currentTimeMillis()+fileName.substring(fileName.lastIndexOf("."));
        File filePath = new File("E:\\Users\\tan\\Desktop\\upload");
        if(!filePath.exists()){
            filePath.mkdirs();
        }
        String path = filePath+"/"+fileName;
        part.write(path);
        return fileName;
    }
}
